import nattyFetch from 'natty-fetch';

const { API_URL,MOCK_URL } = require(`./../config/${ENV}.json`);
const context = nattyFetch.context({
  mockUrlPrefix: MOCK_URL,
  urlPrefix: API_URL,
  mock: false,
  withCredentials: false,
  traditional: true,
  data: {
    _wx_token_: '',
  },
  timeout: 15000,
  // 请按照需要开启
  fit: function (response) {
    let ret = {
      success: response.success
    };
    if (ret.success) {
      ret.content = response.data;
    } else {
      ret.error = {
        message: response.msg
      }
    }
    return ret;
  }
});

context.create('WechatAPI', {

  //获取配置
  auth: {
    url: 'wechat/api/sign',
    method: 'POST',
    header: {
      'Content-Type': 'application/json;charset=utf-8'
    },
  },

  //获取用户信息
  getUser: {
    mock: false,
    url: 'wechat/get/user',
    method: 'GET',
  },

  //绑定用户信息
  binding: {
    url: 'wechat/user/binding',
    method: 'POST',
    header: {
      'Content-Type': 'application/json;charset=utf-8'
    },
  },

  //绑定用户信息
  sendVcode: {
    url: 'wechat/message/vcode/send',
    method: 'GET'
  },

  userIsBinding: {
    url: 'wechat/user/isBinding',
    method: 'GET'
  }

});


export default context.api;
